﻿using ServiceOperater.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace ServiceOperater.Converters
{
    // 右边Service,Action区域的ItemSource属性转换
    // 确保右侧的DataContext永远是ServiceTreeNodeViewModel
    public sealed class AnalysisResultViewLeftAreaItemsSourceConverter : IValueConverter
    {
        public static IValueConverter INSTANCE = new AnalysisResultViewLeftAreaItemsSourceConverter();

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is FileTreeNodeViewModel))
            {
                return null;
            }

            var selectedFvm = (value as FileTreeNodeViewModel);
            if (selectedFvm.IsDirectory)
            {
                return selectedFvm.Children;
            }
            else
            {
                return selectedFvm.ServiceCollection;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
